package maze;

public class MazeMoveCommand implements UndoableCommand{

	private Maze maze;
	private Direction dir;
	
	public MazeMoveCommand(Maze maze,Direction dir) {
		this.maze = maze;
		this.dir = dir;
	}
	
	private void move(Maze maze , Direction dir)
	{
		Room curRoom = maze.getCurrentRoom();
		MapSite side = curRoom.getSide(dir);
		side.enter();
		if (side instanceof Room)
			maze.setCurrentRoom((Room)side);
		else if (side instanceof Door) {
			maze.setCurrentRoom(((Door)side).getOtherSide(curRoom));
			maze.getCurrentRoom().enter();
		}
	}
	
	@Override
	public void execute() {
		
		move(maze,dir);
		
	}

	@Override
	public void undo() {
		
		move(maze,dir.opposite());
		
	}
	
}
